<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
       div {
           margin: 10px;
       }
        .red {
            background: red;
        }
        /*串联选择器*/
        .red.green {
            background: green;
        }
    </style>
</head>
<body>
<div>This div should be white</div>
<div class="red">This div will be green because it now has the "green" and "red" classes. It would be red if the addClass function failed.</div>
<div>This div should be white</div>
<p>There is one green div</p>
<script src="jquery-1.12.4.js" type="text/javascript"></script>
<script>
    $('div').addClass(function (index, currentClass) {
        var addClass;
        if (currentClass === 'red') {
            addClass = 'green';
            $('p').text('There is one green div');
        }
        return addClass;
    })
</script>
</body>
</html>